home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / sources.arc / DANG_SRC.LZH / SELECT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-17  |  19.7 KB  |  798 lines

  1. /*  loads up main selection screen
  2.  
  3.     user can select 
  4.  
  5.        1 -enter city
  6.        2 -load char
  7.        3 -save char
  8.        4 -roll a char     
  9.    */
  10.  
  11. struct character
  12.         {
  13.          char name[15]; /* NO! Set these to char *name and then */
  14.          char align[15]; /* name = "blahh.." OR do char name[]="blah!" */
  15.          char class[15];  /* you're defining an array of one element */
  16.          int lvl;         /* thats a ptr to a char! too redundant! */
  17.          long int exp;
  18.          long int hp;
  19.          int ac,str,inte,wis,dex,con;
  20.          int weapon_num,armor_num;
  21.          int backpack[10];       /* holds unique #. I'll have 1 
  22.                                     main array that will hold number,
  23.                                     name so we can look it up. Set to -1, means EMPTY */
  24.          char weapon[15];
  25.          char armor[15];
  26.          char spell[15];
  27.          long int max_hp,max_sp;
  28.          int spell_num;
  29.          long int sp;
  30.          long int gold;
  31.          int user_items[25];  /* holds food,h2o,keys,etc.. */
  32.          int current_spells_active[5]; /*0=treasure Finding, 1=Fleetness, 2=Protection
  33.                                          3=Strength 4=Charm */
  34.          int hunger_thurst_status[2];  /*0 not hungry/thirsty.. 10 FAMISHED */
  35.                                        /* 0 is hunger 1 is thirst */
  36.          long int bank_balance;  
  37.          int x_loc,y_loc,        /* current x,y location */
  38.              weather,count,way,time,loc,current_sky,
  39.              current_sound,clock,am_pm,sound;
  40.          char dir; 
  41.          };
  42.  
  43.  
  44.  struct character user;
  45.  char name[20],align,class;
  46.  
  47.  
  48. int  buffer[200];        /* holds the char info for disk loading and saving */
  49. int pointer[37];
  50.  
  51.  
  52.  
  53. #define rnd(t) abs(Random()%(t))   /*returns a number from 0 to (t-1) */
  54.  
  55. char     temp_[32000],                     /* Temp buffer where file is read in    */
  56.          *hld,
  57.          *iff_in, *iff_out;                  /* Pointers for DEGAS unpack() routine    */
  58.  
  59. #include <stdio.h>
  60. #include <gemdefs.h>
  61. #include <osbind.h>
  62.  
  63. int contrl[12];
  64. int intin[256],  ptsin[256];
  65. int intout[256], ptsout[256];
  66.  
  67.  
  68. int savepal[16],newpal[16],junkbuff[46];
  69. int filehandle;
  70. char input[] = "select.pc1";
  71. int handle;
  72. int button,x,y;
  73. int stats[10];
  74. int choice;           /* if == 1 then you rolled and accepted a character */
  75.  char pix1[]  ="START0.DAT";
  76.  char pix2[]  ="START1.DAT";
  77.  
  78. main()
  79.  
  80. {
  81.     char command[20];
  82.     char *scr1,*scr2,*scr3,*screen;
  83.     char in;
  84.     int type;
  85.    
  86.     MFDB    theMFDB;    /*  Screen definition structure  */
  87.     char string[30];
  88.  
  89.     appl_init();
  90.     handle = open_workstation(&theMFDB);
  91.     
  92. v_hide_c(handle);   /*hide the mouse */
  93.  
  94. pt_set(pointer,4,2);
  95. pointer[2]=1;
  96. pointer[3]=3;
  97. pointer[4]=2;
  98. stuffbits(&pointer[5],"0000000000000000");
  99. stuffbits(&pointer[6],"0001111100000000");
  100. stuffbits(&pointer[7],"0001111000000000");
  101. stuffbits(&pointer[8],"0001000110000000");
  102. stuffbits(&pointer[9],"0000000001100000");
  103. for(type=10;type<21;type++)
  104. stuffbits(&pointer[type],"0000000000000000");
  105.  
  106. stuffbits(&pointer[5],"0000000000000000");
  107. stuffbits(&pointer[6],"0011111000000000");
  108. stuffbits(&pointer[7],"0011110000000000");
  109. stuffbits(&pointer[8],"0011001110000000");
  110. stuffbits(&pointer[9],"0000000011100000");
  111. for(type=10;type<21;type++)
  112. stuffbits(&pointer[type],"0000000000000000");
  113.  
  114.  
  115.    scr1 = malloc(32768+256);  /*allocate memory for 2nd screen */
  116.     if ((long) scr1 & 0xff)
  117.       scr1 = scr1 + (0x100 - (long)scr1 & 0xff);
  118.  
  119. screen = (char *)Physbase();          /* get ptr to physbase */
  120. type = 2; /* *.pc1 pic */
  121.  
  122. read_stuff(pix1,scr1,type);   /* intro screen */
  123. Setscreen(scr1,scr1,-1);    /* display the pic */
  124. Setpalette(newpal);        /* tel sys to use these colors! */
  125. command[0] = strlen("intro 11000 -q -l");
  126. strcpy(&command[1],"intro 11000 -q -l");
  127. Pexec(0,"MUSIC",command,command);          /* loop until keypress */
  128. fade_to_black();
  129.  
  130. Setscreen(screen,screen,-1);
  131. read_stuff(pix2,scr1,type);   /* title screen */
  132. Setscreen(scr1,scr1,-1);    /* display the pic */
  133. Setpalette(newpal);        /* tel sys to use these colors! */
  134. in=Bconin(2);
  135. fade_to_black();
  136.  
  137. Setscreen(screen,screen,-1);
  138. read_stuff(input,scr1,type);  /* Selection screen onto the temp scr*/
  139. Setscreen(scr1,scr1,-1);    /* display the pic */
  140. Setpalette(newpal);        /* tel sys to use these colors! */
  141.  
  142. vsc_form(handle,pointer);  /* make our new mouse ptr active */
  143. v_show_c(handle,0);
  144.  do                              /* loop until keypress */
  145.      {
  146.      
  147.   vq_mouse(handle,&button,&x,&y);
  148.  
  149.  
  150.   if(button == 1 && (x>14 && x<42))         /* if left button pressed... */
  151.       {
  152.        if( y>35 && y<61) enter_city(scr1);
  153.        if( y>67 && y<93) load_character();
  154.        if( y>100 && y<127) save_character();
  155.        if( y>134 && y<161) roll();
  156.       }
  157.      } while ( 1 );      /* while no input */
  158. Setscreen(screen,screen,-1);  
  159. Setpalette(savepal);      /* restore palette */
  160.     v_clsvwk(handle);
  161.     appl_exit();
  162. }
  163.  
  164.  
  165.  
  166. /*************************/
  167. load_character()
  168. {FILE *ifp;
  169.  char in;
  170.  int x;
  171.  
  172. clear();
  173. v_gtext(handle,188,37,"Load a Character");
  174. loadchar(buffer);
  175. display();
  176.  
  177. }
  178.  
  179. /************************************/
  180. save_character()
  181. {
  182. FILE *ofp;
  183. char out;
  184. int x;
  185.  
  186. clear();
  187. v_gtext(handle,188,37,"Save a Character");
  188. savechar(buffer);
  189. v_gtext(handle,188,53,"Character saved");
  190. }
  191.  
  192.  
  193. /******************************8/
  194. stats[] 
  195. */         
  196. roll()
  197.  
  198. {
  199. int x;
  200.  
  201. clear();
  202. v_gtext(handle,188,37,"Roll a Character");
  203.  
  204. do
  205. {
  206. choice = 0;          /* reset choice to 0 */
  207.  
  208. user.lvl = 1;
  209. user.exp = 0L;
  210. user.ac  = 15;
  211. user.weapon_num = 0;
  212. user.armor_num = 0;
  213. user.spell_num = 0;
  214. user.bank_balance = 0L;
  215. user.x_loc = 19;               /* x,y location */
  216. user.y_loc = 16;
  217. user.weather = 0;
  218. user.time = 0;
  219. user.count = 1;
  220. user.way = 1;
  221. user.loc = 206;       /* initial room # */
  222. user.current_sky = 0;
  223. user.current_sound = 0;
  224. user.sound = 1;
  225. user.clock = 1;
  226. user.am_pm = 1;
  227. user.dir = 'N';       /* face north! */
  228.  
  229. for(x=0;x<10;x++) user.backpack[x] = -1;
  230. for(x=0;x<25;x++) user.user_items[x] = 0;
  231. for(x=0;x<2;x++) user.hunger_thurst_status[x] = 0;
  232.  
  233. user.str = user.inte = user.wis = user.dex = user.con = 7; /* base */
  234. user.str  += rnd(12);
  235. user.inte += rnd(12);
  236. user.wis  += rnd(12);
  237. user.dex  += rnd(12);
  238. user.con  += rnd(12);
  239.  
  240. user.hp = user.sp = user.gold = 5L; /* base */
  241. user.hp += (long int) rnd(20);
  242. user.sp += (long int) rnd(20);
  243. user.gold += (long int) rnd(20);
  244.  
  245. user.max_hp = user.hp;
  246. user.max_sp = user.sp;
  247.  
  248. strcpy(user.weapon,"None");
  249. strcpy(user.armor,"None");
  250. strcpy(user.spell,"None");
  251.  
  252. display();
  253.  
  254. v_gtext(handle,188,141,"Accept");
  255. v_gtext(handle,248,141,"Reroll");
  256.  
  257.  do               /* loop until mouse press */
  258.      {
  259.      
  260.       vq_mouse(handle,&button,&x,&y);
  261.       if( button == 1 && (y>133 && y<150))  /* if left button pressed and in y range */ 
  262.          {
  263.          
  264.           if(x > 187 && x<230) choice = 1;  /* accept!! */
  265.           if(x >247 && x < 320) choice = -1; /* reroll */
  266.          }
  267.      }while(choice == 0);
  268.  
  269. }while(choice == -1);     /* reroll */
  270.  
  271. v_hide_c(handle);   /*hide the mouse */
  272.  
  273.  
  274. if( choice == 1 )
  275.   {
  276.     clear();
  277.     vs_curaddress(handle,7,30);
  278.     v_gtext(handle,188,54,"Name:");
  279.     Cconrs(name);
  280.     clear();
  281.     v_gtext(handle,188,53,"Alignment:");
  282.     v_gtext(handle,188,61,"G)ood");
  283.     v_gtext(handle,188,69,"N)eutral");
  284.     v_gtext(handle,188,77,"E)vil");
  285.     do
  286.     {
  287.     align = Bconin(2);
  288.     } while( (align != 'G' && align != 'g')  && (align != 'N' && align != 'n') 
  289.              && (align != 'E' && align != 'e') );
  290.     clear();
  291.     v_gtext(handle,188,53,"Class:");
  292.     v_gtext(handle,188,61,"F)ighter");
  293.     v_gtext(handle,188,69,"M)age");
  294.     v_gtext(handle,188,77,"T)hief");
  295.    
  296.    do
  297.     {
  298.     class = Bconin(2);
  299.     } while( (class != 'F' && class != 'f')  && (class != 'M' && class != 'm') 
  300.              && (class != 'T' && class != 't') );
  301.  
  302.  
  303.  
  304.     strcpy(user.name,&(name[2]));
  305.     if(align == 'G' || align == 'g') strcpy(user.align,"Good");
  306.     if(align == 'N' || align == 'n') strcpy(user.align,"Neutral");
  307.     if(align == 'E' || align == 'e') strcpy(user.align,"Evil");
  308.     if(class == 'F' || class == 'f') strcpy(user.class,"Fighter");
  309.     if(class == 'M' || class == 'm') strcpy(user.class,"Mage");
  310.     if(class == 'T' || class == 't') strcpy(user.class,"Thief");
  311.     clear();
  312.     v_gtext(handle,188,53,"Be sure to SAVE");
  313.     v_gtext(handle,188,61,"your character..");
  314.   }
  315.  v_show_c(handle,0);
  316. }
  317. /****************************/
  318. display()
  319. {
  320.  char string[30];
  321.  
  322.  
  323. clear();
  324. v_gtext(handle,188,53,user.name);
  325. v_gtext(handle,188,61,user.align);
  326. v_gtext(handle,188,69,user.class);
  327. if(user.str < 10)
  328. sprintf(string,"     STR: %d",user.str);
  329. else
  330. sprintf(string,"     STR:%d",user.str);
  331. v_gtext(handle,188,77,string);
  332.  
  333. if(user.dex < 10)
  334. sprintf(string,"     DEX: %d",user.dex);
  335. else
  336. sprintf(string,"     DEX:%d",user.dex);
  337. v_gtext(handle,188,85,string);
  338.  
  339. if(user.inte < 10)
  340. sprintf(string,"     INT: %d",user.inte);
  341. else
  342. sprintf(string,"     INT:%d",user.inte);
  343. v_gtext(handle,188,93,string);
  344.  
  345. if(user.wis < 10)
  346. sprintf(string,"     WIS: %d",user.wis);
  347. else
  348. sprintf(string,"     WIS:%d",user.wis);
  349. v_gtext(handle,188,101,string);
  350.  
  351. if(user.con < 10)
  352. sprintf(string,"     CON: %d",user.con);
  353. else
  354. sprintf(string,"     CON:%d",user.con);
  355. v_gtext(handle,188,109,string);
  356.  
  357.  
  358. if(user.hp < 10L)
  359. sprintf(string,"     HP : %ld",user.hp);
  360. else
  361. sprintf(string,"     HP :%ld",user.hp);
  362. v_gtext(handle,188,117,string);
  363.  
  364. if(user.sp < 10L)
  365. sprintf(string,"     SP : %ld",user.sp);
  366. else
  367. sprintf(string,"     SP :%ld",user.sp);
  368. v_gtext(handle,188,125,string);
  369.  
  370. }
  371. /****************************/
  372. clear()
  373. {
  374.  int h,y=37;
  375.  
  376.  
  377.      
  378. for(h=0;h<14;h++)
  379. {
  380. v_gtext(handle,188,y,"                ");
  381. y +=8;
  382. }
  383.  
  384. }
  385. /***************************/
  386. enter_city(scr1)
  387. char *scr1;
  388. {
  389.  
  390. free(scr1);
  391. clear();
  392. v_gtext(handle,188,45,"Loading....");
  393. Pexec(0,"CITY","","");
  394. exit(1);                        /* and quit when exit city */
  395.  }
  396.  
  397.  
  398.  
  399. /* load degas compressed pics */
  400.  
  401. /************************/
  402. read_stuff(hold,adrr,type)
  403. char hold[];
  404. register char *adrr;
  405. int type;
  406.  
  407. {
  408.  char buf[130];
  409.  int lines,i;
  410.  
  411.  
  412. filehandle = Fopen(hold,0); 
  413.  
  414. for(i=0; i<16;i++)
  415.  savepal[i]=Setcolor(i,-1);
  416.  
  417. /* read header data */
  418. i=Fread(filehandle,2L,buf);
  419.  
  420.  
  421. /* read 16 words(32 bytes) of palette data into newpal array */
  422. i =Fread(filehandle,32L,newpal);
  423.  
  424.  
  425. if(type == 1)                       /* if .pi1 pic */
  426.  {
  427.    i =Fread(filehandle,32000L,adrr);/* read pic image in */ 
  428.    /* Close file */
  429.    Fclose(filehandle);
  430.    return(1);                       /* and quit */
  431.  } 
  432.  
  433.                                    /* else it's compressed.. */
  434. i=Fread(filehandle,32000L,temp_);  /* read image onto back screen*/
  435. /* Close file */
  436. Fclose(filehandle);
  437.  
  438.                                   
  439.  
  440.      lines = 200;                     /* Low, med-res    */
  441.                  iff_in  = temp_;                /* iff_in pts to temp_buf*/
  442.                  iff_out = adrr;      /* iff_out pts to pic_buffer*/
  443.                   do        
  444.          unpack(0);                                      /* Unpack a line at a time */
  445.                   while (--lines); 
  446.  
  447.     
  448. }
  449. /************************/
  450.  
  451. /***********************/
  452.  
  453. /*---------------------------------------------------------------------------*/
  454. /*                             |--------- DEGAS ---------|            */
  455. /*                              UNCOMPRESSED   COMPRESSED            */
  456. /*                 NEO  low med mono   low med mono     TINY    */
  457. /*    typ...        0     1   2   3     4   5   6     7        */
  458.  
  459. /* Unpacks a single scan line & updates iff_in & iff_out global pointers
  460.  
  461.                      /    byt ==  0 to  127  copy next [byt+1] bytes
  462. Unpack routine --if-<    byt == -1 to -127  copy next byte [-byt+1] times
  463.                      \    byt == 128         NO-OP                            */
  464.  
  465. unpack(rez)
  466. int     rez;
  467.  
  468. {
  469.     register char     *src_ptr, *dst_ptr,           /* ptrs to source/dest */
  470.               byt, cnt;                     /* byt holds the ACTUAL compressed data code(control byte ) */
  471.     register int      minus128 = -128, 
  472.               len;                          
  473.     char                 linbuf[320];                            /* Oversize just in case! */
  474.     int                      llen;
  475.  
  476.  
  477.     if (rez < 2)     len = 160;
  478.     else             len = 80;
  479.     llen = len;
  480.     src_ptr = iff_in;           /* iff_in is ptr to compressed data */
  481.     dst_ptr = &linbuf[0];       /* linbuf WILL hold an ENTIRE Uncompressed scan line. 4 bitplanes * 80 = 320 max! */ 
  482.  
  483.     while (len > 0)
  484.    {
  485.             byt = *src_ptr++;       /* get byte value at address scr_ptr, THEN inc scr_ptr+1 */
  486.             if (byt >= 0)           /* If ctrl code >= 0 then use the next x+1 bytes*/
  487.     {
  488.                  ++byt;                 /* inc byt +1 */
  489.                   do 
  490.        {
  491.                         *dst_ptr++ = *src_ptr++;  /* get byte value from address source, and inc the 2 ptrs */
  492.                         --len;                    /* one byte down.. */
  493.                    }
  494.          while (--byt);           /* do this byt TIMES (remember byt here = byt+1 */
  495.              }
  496.              else 
  497.        if (byt != minus128)       /* else if ctrl code NOT = -128*/
  498.          {                        /*Then use the next byte -x+1 times, (-x) cause x will be negative and - - = + */
  499.                       cnt = -byt + 1;         /* cnt = -x + 1 */
  500.                       byt = *src_ptr++;       /* byt = THE very next byte past the ctrl code(or ctrl byte! */
  501.                        do {
  502.                                *dst_ptr++ = byt;  /* store that byte */
  503.                                --len;         
  504.                           }
  505.                while (--cnt);    /* keep doing it cnt times */
  506.                   }
  507.         }
  508.  
  509.     ilbm_st(linbuf, iff_out, rez);   /* convert the format line */
  510.     iff_in = src_ptr;                                    /* Update global pointers */
  511.     iff_out += llen;
  512.  
  513. }                                /* end of module uncompress() */
  514.  
  515. /*---------------------------------------------------------------------------*/
  516.  
  517. ilbm_st(src_ptr, dst_ptr, rez)           /* Convert ILBM format line to ST format */
  518. int         *src_ptr, *dst_ptr, rez;
  519. {
  520.     int         x, *p0_ptr, *p1_ptr, *p2_ptr, *p3_ptr;
  521.  
  522.     if (rez==0) 
  523.  {                                                     /* Low-res */
  524.   
  525.         p0_ptr = src_ptr;
  526.         p1_ptr = src_ptr + 20;
  527.         p2_ptr = src_ptr + 40;
  528.         p3_ptr = src_ptr + 60;
  529.         for (x=0; x<20; ++x)
  530.   {
  531.                *dst_ptr++ = *p0_ptr++;
  532.                *dst_ptr++ = *p1_ptr++;
  533.                *dst_ptr++ = *p2_ptr++;
  534.                *dst_ptr++ = *p3_ptr++;
  535.           }
  536.     } 
  537.  else if (rez==1) 
  538.   {                                            /* Med-res */
  539.            p0_ptr = src_ptr;
  540.            p1_ptr = src_ptr + 40;
  541.            for (x=0; x<40; ++x)
  542.     {
  543.                  *dst_ptr++ = *p0_ptr++;
  544.                  *dst_ptr++ = *p1_ptr++;
  545.             }
  546.     }
  547.     else 
  548.      {                                                   /* Monochrome */
  549.               for (x=0; x<40; ++x)
  550.                   *dst_ptr++ = *src_ptr++;
  551.          }
  552.  
  553.  }
  554. /*---------------------------------------------------------------------------*/
  555.  
  556.  
  557. fade_to_black()
  558. {
  559.  int h;
  560.  
  561.   for(h=0;h<16;h++)
  562.     Setcolor(h,0x000);
  563.  
  564.    }
  565. /**********************/
  566.  
  567.  
  568. /* 
  569.   the load and save character routines.
  570.  
  571. */
  572.  
  573.  
  574.  
  575.  
  576.  
  577. /*********************/
  578. loadchar(i)
  579. int i[];
  580. {
  581. long int hold;
  582. int k,fd;
  583.  
  584.  if( (fd = Fopen("char.dat",2)) < 0) printf("Error cant open file\n"); 
  585.  
  586.  Fread(fd,(long)400,i); /* read 400 bytes*/
  587.  
  588.  
  589.   strcpy(user.name,i); 
  590.   strcpy(user.align,&i[15]);
  591.   strcpy(user.class,&(i[30]));
  592.   user.lvl= i[45];
  593.   
  594.  
  595.   create_LW_from_two_words( &user.exp, i[46], i[48] );
  596.  
  597.  
  598.   user.ac = i[51];
  599.  
  600.   create_LW_from_two_words( &user.hp, i[52], i[54] );
  601.  
  602.   user.str =i[56];
  603.   user.inte=i[57];
  604.   user.wis=i[58];
  605.   user.dex=i[59];
  606.   user.con=i[60];
  607.   user.weapon_num=i[61];
  608.   user.armor_num=i[62];
  609.   for(k=0;k<10;k++)
  610.    user.backpack[k]=i[63+k];
  611.   
  612.   strcpy(user.weapon,&(i[73]));
  613.   strcpy(user.armor,&(i[88]));
  614.   strcpy(user.spell,&(i[103]));
  615.  
  616.   create_LW_from_two_words( &user.max_hp, i[118], i[120] );
  617.  
  618.   create_LW_from_two_words( &user.max_sp, i[122], i[124] );
  619.  
  620.  
  621.   user.spell_num=i[126];
  622.  
  623. create_LW_from_two_words( &user.sp, i[127], i[129] );
  624.  
  625. create_LW_from_two_words( &user.gold, i[131], i[133] );
  626.  
  627.   for(k=0;k<25;k++)
  628.    user.user_items[k]=i[135+k];
  629.   for(k=0;k<5;k++)
  630.    user.current_spells_active[k]=i[160+k];
  631.   for(k=0;k<2;k++)
  632.    user.hunger_thurst_status[k]=i[165+k];
  633.  
  634.  
  635.  
  636.  create_LW_from_two_words( &user.bank_balance, i[168], i[170] );
  637.    
  638.  
  639.   user.x_loc=i[173];
  640.   user.y_loc=i[174];
  641.   user.weather=i[175];
  642.  user.count=i[176];
  643.   user.way=i[177];
  644.   user.time=i[178];
  645.   user.loc=i[179];
  646.   user.current_sky=i[180];
  647.   user.current_sound=i[181];
  648.   user.clock=i[182];
  649.   user.am_pm=i[183];
  650.   user.sound=i[184];
  651.   user.count=i[185];
  652.   user.dir=i[186];
  653.  
  654.  Fclose(fd);
  655.  
  656. }
  657.  
  658.  
  659.  
  660. /*********************/
  661. /* ints are 2 bytes
  662.    chars are 1 byte 
  663.    longs are 4 bytes 
  664.  
  665.    ALL strings must be terminated with \0 or NULL!!!
  666.  
  667. */
  668.  
  669. savechar(b)
  670. int b[];
  671. {
  672. int pp,k,fd;
  673.  
  674.  
  675.  
  676.   strcpy(b,user.name);
  677.   strcpy(&b[15],user.align);
  678.   strcpy(&(b[30]),user.class);
  679.   b[45] = user.lvl;
  680.  
  681.   
  682.   extract_LW_into_two_words( user.exp,&(b[46])  , &(b[48]));
  683.     
  684.  
  685.   b[51] = user.ac;
  686.   extract_LW_into_two_words( user.hp , &(b[52]) , &(b[54]) );
  687.  
  688.   b[56]=user.str;
  689.   b[57]=user.inte;
  690.   b[58]=user.wis;
  691.   b[59]=user.dex;
  692.   b[60]=user.con;
  693.   b[61]=user.weapon_num;
  694.   b[62]=user.armor_num;
  695.   for(k=0;k<10;k++)
  696.    b[63+k]=user.backpack[k];
  697.   
  698.   strcpy(&(b[73]),user.weapon);
  699.   strcpy(&(b[88]),user.armor);
  700.   strcpy(&(b[103]),user.spell);
  701.  
  702.   extract_LW_into_two_words( user.max_hp , &(b[118]) , &(b[120]) );
  703.   extract_LW_into_two_words( user.max_sp , &(b[122]) , &(b[124]) );
  704.  
  705.   b[126]=user.spell_num;
  706.  
  707.   
  708.   extract_LW_into_two_words( user.sp , &(b[127]) , &(b[129]) );
  709.  
  710.   extract_LW_into_two_words( user.gold , &(b[131]) , &(b[134]) );
  711.  
  712.  
  713.   for(k=0;k<25;k++)
  714.    b[135+k]=user.user_items[k];
  715.   for(k=0;k<5;k++)
  716.    b[160+k]=user.current_spells_active[k];
  717.   for(k=0;k<2;k++)
  718.    b[165+k]=user.hunger_thurst_status[k];
  719.    
  720. extract_LW_into_two_words( user.bank_balance , &(b[168]) , &(b[170]) );
  721.  
  722.  
  723.   b[173]=user.x_loc;   /* global x&y coords _ OTHERS*/
  724.   b[174]=user.y_loc;
  725.   b[175]=user.weather;
  726.   b[176]=user.count;
  727.   b[177]=user.way;
  728.   b[178]=user.time;
  729.   b[179]=user.loc;
  730.   b[180]=user.current_sky;
  731.   b[181]=user.current_sound;
  732.   b[182]=user.clock;
  733.   b[183]=user.am_pm;
  734.   b[184]=user.sound;
  735.   b[185]=user.count;
  736.   b[186]=user.dir;
  737.  
  738.  if( (fd = Fopen("char.dat",2)) < 0) printf("Error cant open file\n"); 
  739.  
  740.  Fwrite(fd,(long)400,b); /*write 9 bytes to file */
  741.  
  742.  Fclose(fd);
  743.  
  744.  
  745. }
  746.  
  747. /*************************************************************/
  748.  
  749.  
  750. extract_LW_into_two_words( data , MSW , LSW )
  751. long int data;
  752.      int *MSW,*LSW;
  753.  
  754. /* This procedure will take a longword(data) and break
  755.    it up into 2 words
  756.  
  757.    Input: data --> the long word
  758.   Output: MSW  --> the Most Signifigant Word
  759.           LSw  --> the Least Sig. Word
  760.  
  761.  
  762. */
  763. {
  764.  long int result; 
  765.  
  766.                                    /* Extract MSW */
  767.   result = data & 0xffff0000;
  768.   result = result >> 16;
  769.    *MSW = result;                        /* store it in an int */
  770.  
  771.  result = data & 0x0000ffff;          /* extract LSW */
  772.  *LSW = result;                          /*store it */
  773.   
  774.  
  775.  }
  776.  
  777. /**********************************************************/
  778.  
  779. create_LW_from_two_words( result, MSW, LSW )
  780. /* Creates a long word from two words */
  781. long int *result;
  782.      int MSW,LSW;
  783. {
  784.  long int lower_word;
  785.                                  /* This code will form a long int
  786.                                    from 2 ints */
  787.  *result = MSW;                        /* get MSW */
  788.  *result = *result << 16;                 /* put into upper word */
  789.  lower_word = LSW;                          /* get LSW */
  790.  lower_word = lower_word & 0x0000ffff;          /* it gets sign extended, so mask
  791.                                        out upper word */
  792.  
  793.  *result +=lower_word;                       /* add to get final result */
  794.  
  795.  
  796.  
  797. }
  798.